<?php
namespace App\Libraries\Decorator\Tool;


use App\Libraries\Decorator\DecoratorInterface\ModelDecorator;

class IsEndDecorator implements ModelDecorator
{

    public function before(){
        //todo
    }

    public function after(&$data){
        if(!is_array($data)){
            $data = json_decode(json_encode($data), true);
        }
        if (isset($data['list']) && isset($data['page_size'])) {
            // 一维数组
            if(count($data['list']) > $data['page_size']){
                array_pop($data['list']);
                $data['is_end'] = 0;
            }else{
                $data['is_end'] = 1;
            }
        } else {
            // 多维数组
            if(is_array($data)){
                foreach($data as &$v){
                    $this->after($v);
                }
            }
        }
        return $data;
    }
}